﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using Common.Utilities;
using Common.Utilities.TextMatch;

namespace Workflows.Components.ETL
{
    /// <summary></summary>
    public class CitationMLAStyles
    {
        /// <summary></summary>
        public Dictionary<int, PatternWeight> JournalArticle { get; set; }
        /// <summary></summary>
        public Dictionary<int, PatternWeight> Book_Article { get; set; }
        /// <summary></summary>
        public Dictionary<int, PatternWeight> Website_Article { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public CitationMLAStyles()
        {
            PatternWeight authorPattern = new PatternWeight()
            {
                Key = Citation.AuthorField,
                Pattern = RegexPatterns.PersonName_LastFM_Multiple,
                Required = true,
                Weight = 1,
                MultiMatches = true
            };
            PatternWeight titlePattern = new PatternWeight()
            {
                Key = Citation.TitleField,
                Pattern = "\"?[^.?!]+\"?",
                Required = false,
                Weight = 0
            };
            PatternWeight journalPattern = new PatternWeight()
            {
                Key = Citation.JournalField,
                Pattern = "[a-zA-Z\\s\\.]+",
                Required = true,
                Weight = 0.9
            };
            PatternWeight volumePattern = new PatternWeight()
            {
                Key = Citation.VolumeField,
                Pattern =
                    "\\d+[\\.:]?|" +
                    RegexPatterns.Months + "|" +
                    RegexPatterns.Quarters + "|(0[1-9]|1[012])" +
                    "\\s+?(19|20)\\d\\d",
                Required = true,
                Weight = 0.75
            };
            PatternWeight issuePattern = new PatternWeight()
            {
                Key = Citation.IssueField,
                Pattern = "\\(\\d+\\)|\\.\\d+",
                Required = false,
                Weight = 0.3
            };
            PatternWeight pagePattern = new PatternWeight()
            {
                Key = Citation.PageField,
                Pattern = "\\d+-*\\d*",
                Required = false,
                Weight = 0.4
            };
            PatternWeight pubTimePattern = new PatternWeight()
                                               {
                                                   Key = Citation.PubTimeField,
                                                   Pattern = "\\(?(19|20)\\d\\d\\)?" + "|" +
                                                             RegexPatterns.Date_DDMMYYYY + "|" +
                                                             RegexPatterns.Date_MMDDYYYY + "|" +
                                                             RegexPatterns.Date_MMMDDYYYY + "|" +
                                                             RegexPatterns.Date_MMMYYYY + "|" +
                                                             RegexPatterns.Date_Quater + "|" +
                                                             RegexPatterns.Date_YYYYMMDD,
                                                   Required = true,
                                                   Weight = 0.5
                                               };

            Dictionary<int, PatternWeight> journalPatterns = new Dictionary<int, PatternWeight>();
            journalPatterns.Add(1, authorPattern);
            journalPatterns.Add(2, titlePattern);
            journalPatterns.Add(3, journalPattern);
            journalPatterns.Add(4, volumePattern);
            journalPatterns.Add(5, issuePattern);
            journalPatterns.Add(6, pubTimePattern);
            journalPatterns.Add(7, pagePattern);
            this.JournalArticle = journalPatterns;

            Dictionary<int, PatternWeight> bookPatterns = new Dictionary<int, PatternWeight>();
            bookPatterns.Add(1, authorPattern.Clone());
            bookPatterns.Add(2, titlePattern.Clone());
            bookPatterns.Add(3, journalPattern.Clone());
            bookPatterns.Add(4, pubTimePattern.Clone());
            PatternWeight pagePattern2 = pagePattern.Clone();
            pagePattern2.Pattern = "\\(?pp\\.\\s+\\d+-?\\d*\\)?";
            bookPatterns.Add(5, pagePattern2);
            this.Book_Article = bookPatterns;

            Dictionary<int, PatternWeight> websitePatterns = new Dictionary<int, PatternWeight>();
            websitePatterns.Add(1, authorPattern.Clone());
            websitePatterns.Add(2, titlePattern.Clone());
            websitePatterns.Add(3, pubTimePattern.Clone());
            PatternWeight urlPattern = new PatternWeight()
            {
                Key = Citation.JournalField,
                Pattern = RegexPatterns.URL,
                Required = true,
                Weight = 1
            };
            websitePatterns.Add(4, urlPattern);
            this.Website_Article = websitePatterns;
        }
    }
}
